<?php

/**
 * MVM_MALL 网上商店系统 后台管理菜单
 * ============================================================================
 * 版权所有 (C) 2007-2010 www.mvmmall.com，并保留所有权利。
 * 网站地址: http://www.mvmmall.com
 * ----------------------------------------------------------------------------
 * 这是一个免费开源的软件；这意味着您可以在不用于商业目的的前提下对程序代码
 * 进行修改、使用和再发布。
 * ============================================================================
 * $Author:  www.mvmmall.com  $
 * $Date: 2008-11-12 $
 * $Id: admin_menu.inc.php  www.mvmmall.com$
 * ---------------------------------------------
*/

if(!defined('MVMMALL') || !defined('IN_ADMINCP')) exit('Access Denied');
if ($action=='list'){
	$arr_tree = $cache->get_cache('menu_tree');
	require_once template('admin_menu');
	footer();
} elseif($action=='add'){
    if($setp==1&&$_POST){
        $use_home   = (int)$use_home;
        $menu_id    = (int)$menu_id;
        $menu_order = (int)$menu_order;
        $menu_name  = dhtmlchars($menu_name);
        $menu_url   = dhtmlchars($menu_url);
        if ($menu_id>0) {
        	require_once MVMMALL_ROOT.'./include/category_tree.class.php';
        	$tree = new tree();
        	$tree->arr_tree = $cache->get_cache('menu_tree');
        	$tree->get_layer($menu_id)==2 && exit('不能在添加菜单');
        }
        $query = " INSERT INTO `{$tablepre}admin_menu` SET
                      menu_id         = '$menu_id',
                      menu_name       = '$menu_name',
                      use_home        = '$use_home',
                      menu_order      = '$menu_order',
                      menu_url        = '$menu_url'";
        $db->query($query);
        $cache->put_cache('menu_tree');
        admin_msg('success','admincp.php?module=admin_menu&action=list');
    } else {
       $admin_menu = admin_menu('menu_id',$menu_id);
       require_once template('admin_menu_add');
       footer();
   }
} elseif($action=='edit' && is_numeric($uid)){
    $menu_rt = $db->get_one("SELECT * FROM `{$tablepre}admin_menu` WHERE uid='$uid'");
    if($setp==1&&$_POST){
        $use_home   = (int)$use_home;
        $menu_id    = (int)$menu_id;
        $menu_order = (int)$menu_order;
        $menu_name  = dhtmlchars($menu_name);
        $menu_url   = dhtmlchars($menu_url);
        if ($menu_id>0) {
        	require_once MVMMALL_ROOT.'./include/category_tree.class.php';
        	$tree = new tree();
        	$tree->arr_tree = $cache->get_cache('menu_tree');
        	$tree->get_layer($menu_id)==2 && exit('不能在添加菜单');
        }
        $query = " UPDATE `{$tablepre}admin_menu` SET
                      menu_id         = '$menu_id',
                      menu_name       = '$menu_name',
                      use_home        = '$use_home',
                      menu_order      = '$menu_order',
                      menu_url        = '$menu_url'
                      WHERE uid = '$uid'";
        $db->query($query);
        $cache->put_cache('menu_tree');
        admin_msg('success','admincp.php?module=admin_menu&action=list');
    } else {
        @extract($menu_rt,EXTR_OVERWRITE);
        $admin_menu = admin_menu('menu_id',$menu_id);
        drop_check($use_home,'use_home');
        require_once template('admin_menu_add');
        footer();
   }
} elseif ($action=='del' && is_numeric($uid)) {
	$db->query("DELETE FROM `{$tablepre}admin_menu` WHERE uid='$uid'");
	$cache->put_cache('menu_tree');
	admin_msg('success',dreferer());
}
else {
    admin_msg('pass_worng');
}

//分类下拉菜单
function admin_menu($name,$select=0,$js='')
{
	
	global $cache;
    $all_str  = "<select name=\"$name\" id=\"$name\"   $js><option selected value=0>----</option>";
    foreach ($cache->get_cache('menu_tree') as $key=>$val)
    {
        $all_str.= " <option value=".$key.' ';
        $key==$select && $all_str.= '  selected';
        $all_str.= ">" .str_repeat( "---", $val[2]) . " " . $val[0] . "</option>\n";
    }
    $all_str .= '</select> ';
    return $all_str;
}
?>
